#pragma once

#include once "winapifamily.bi"
#include once "pshpack1.bi"
#include once "poppack.bi"

extern "C"

#define __USBUSER_H__
#define __USBIODEF_H__
const USB_SUBMIT_URB = 0
const USB_RESET_PORT = 1
const USB_GET_ROOTHUB_PDO = 3
const USB_GET_PORT_STATUS = 4
const USB_ENABLE_PORT = 5
const USB_GET_HUB_COUNT = 6
const USB_CYCLE_PORT = 7
const USB_GET_HUB_NAME = 8
const USB_IDLE_NOTIFICATION = 9
const USB_RECORD_FAILURE = 10
const USB_GET_BUS_INFO = 264
const USB_GET_CONTROLLER_NAME = 265
const USB_GET_BUSGUID_INFO = 266
const USB_GET_PARENT_HUB_INFO = 267
const USB_GET_DEVICE_HANDLE = 268
const USB_GET_DEVICE_HANDLE_EX = 269
const USB_GET_TT_DEVICE_HANDLE = 270
const USB_GET_TOPOLOGY_ADDRESS = 271
const USB_IDLE_NOTIFICATION_EX = 272
const USB_REQ_GLOBAL_SUSPEND = 273
const USB_REQ_GLOBAL_RESUME = 274
const USB_GET_HUB_CONFIG_INFO = 275
const USB_REGISTER_COMPOSITE_DEVICE = 0
const USB_UNREGISTER_COMPOSITE_DEVICE = 1
const USB_REQUEST_REMOTE_WAKE_NOTIFICATION = 2
const HCD_GET_STATS_1 = 255
const HCD_DIAGNOSTIC_MODE_ON = 256
const HCD_DIAGNOSTIC_MODE_OFF = 257
const HCD_GET_ROOT_HUB_NAME = 258
const HCD_GET_DRIVERKEY_NAME = 265
const HCD_GET_STATS_2 = 266
const HCD_DISABLE_PORT = 268
const HCD_ENABLE_PORT = 269
const HCD_USER_REQUEST = 270
const HCD_TRACE_READ_REQUEST = 275
const USB_GET_NODE_INFORMATION = 258
const USB_GET_NODE_CONNECTION_INFORMATION = 259
const USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION = 260
const USB_GET_NODE_CONNECTION_NAME = 261
const USB_DIAG_IGNORE_HUBS_ON = 262
const USB_DIAG_IGNORE_HUBS_OFF = 263
const USB_GET_NODE_CONNECTION_DRIVERKEY_NAME = 264
const USB_GET_HUB_CAPABILITIES = 271
const USB_GET_NODE_CONNECTION_ATTRIBUTES = 272
const USB_HUB_CYCLE_PORT = 273
const USB_GET_NODE_CONNECTION_INFORMATION_EX = 274
const USB_RESET_HUB = 275
const USB_GET_HUB_CAPABILITIES_EX = 276
const USB_GET_HUB_INFORMATION_EX = 277
const USB_GET_PORT_CONNECTOR_PROPERTIES = 278
const USB_GET_NODE_CONNECTION_INFORMATION_EX_V2 = 279
#define GUID_CLASS_USBHUB GUID_DEVINTERFACE_USB_HUB
#define GUID_CLASS_USB_DEVICE GUID_DEVINTERFACE_USB_DEVICE
#define GUID_CLASS_USB_HOST_CONTROLLER GUID_DEVINTERFACE_USB_HOST_CONTROLLER
#define FILE_DEVICE_USB FILE_DEVICE_UNKNOWN
#define USB_CTL(id) CTL_CODE(FILE_DEVICE_USB, (id), METHOD_BUFFERED, FILE_ANY_ACCESS)
#define USB_KERNEL_CTL(id) CTL_CODE(FILE_DEVICE_USB, (id), METHOD_NEITHER, FILE_ANY_ACCESS)
#define USB_KERNEL_CTL_BUFFERED(id) CTL_CODE(FILE_DEVICE_USB, (id), METHOD_BUFFERED, FILE_ANY_ACCESS)

'' TODO: DEFINE_GUID (GUID_DEVINTERFACE_USB_HUB, 0xf18a0e88, 0xc30c, 0x11d0, 0x88, 0x15, 0x00, 0xa0, 0xc9, 0x06, 0xbe, 0xd8);
'' TODO: DEFINE_GUID (GUID_DEVINTERFACE_USB_DEVICE, 0xa5dcbf10, 0x6530, 0x11d2, 0x90, 0x1f, 0x00, 0xc0, 0x4f, 0xb9, 0x51, 0xed);
'' TODO: DEFINE_GUID (GUID_DEVINTERFACE_USB_HOST_CONTROLLER, 0x3abf6f2d, 0x71c4, 0x462a, 0x8a, 0x92, 0x1e, 0x68, 0x61, 0xe6, 0xaf, 0x27);
'' TODO: DEFINE_GUID (GUID_USB_WMI_STD_DATA, 0x4e623b20, 0xcb14, 0x11d1, 0xb3, 0x31, 0x00, 0xa0, 0xc9, 0x59, 0xbb, 0xd2);
'' TODO: DEFINE_GUID (GUID_USB_WMI_STD_NOTIFICATION, 0x4e623b20, 0xcb14, 0x11d1, 0xb3, 0x31, 0x00, 0xa0, 0xc9, 0x59, 0xbb, 0xd2);
type USB_IDLE_CALLBACK as function(byval Context as PVOID) as VOID

type _USB_IDLE_CALLBACK_INFO
	IdleCallback as USB_IDLE_CALLBACK
	IdleContext as PVOID
end type

type USB_IDLE_CALLBACK_INFO as _USB_IDLE_CALLBACK_INFO
type PUSB_IDLE_CALLBACK_INFO as _USB_IDLE_CALLBACK_INFO ptr
const USBUSER_VERSION = &h00000004
#define IOCTL_USB_USER_REQUEST USB_CTL(HCD_USER_REQUEST)
#define IOCTL_USB_DIAGNOSTIC_MODE_ON USB_CTL(HCD_DIAGNOSTIC_MODE_ON)
#define IOCTL_USB_DIAGNOSTIC_MODE_OFF USB_CTL(HCD_DIAGNOSTIC_MODE_OFF)
#define IOCTL_USB_GET_ROOT_HUB_NAME USB_CTL(HCD_GET_ROOT_HUB_NAME)
#define IOCTL_GET_HCD_DRIVERKEY_NAME USB_CTL(HCD_GET_DRIVERKEY_NAME)

type _USB_USER_ERROR_CODE as long
enum
	UsbUserSuccess = 0
	UsbUserNotSupported
	UsbUserInvalidRequestCode
	UsbUserFeatureDisabled
	UsbUserInvalidHeaderParameter
	UsbUserInvalidParameter
	UsbUserMiniportError
	UsbUserBufferTooSmall
	UsbUserErrorNotMapped
	UsbUserDeviceNotStarted
	UsbUserNoDeviceConnected
end enum

type USB_USER_ERROR_CODE as _USB_USER_ERROR_CODE
const USBUSER_GET_CONTROLLER_INFO_0 = &h00000001
const USBUSER_GET_CONTROLLER_DRIVER_KEY = &h00000002
const USBUSER_PASS_THRU = &h00000003
const USBUSER_GET_POWER_STATE_MAP = &h00000004
const USBUSER_GET_BANDWIDTH_INFORMATION = &h00000005
const USBUSER_GET_BUS_STATISTICS_0 = &h00000006
const USBUSER_GET_ROOTHUB_SYMBOLIC_NAME = &h00000007
const USBUSER_GET_USB_DRIVER_VERSION = &h00000008
const USBUSER_GET_USB2_HW_VERSION = &h00000009
const USBUSER_USB_REFRESH_HCT_REG = &h0000000a
const USBUSER_OP_SEND_ONE_PACKET = &h10000001
const USBUSER_OP_RAW_RESET_PORT = &h20000001
const USBUSER_OP_OPEN_RAW_DEVICE = &h20000002
const USBUSER_OP_CLOSE_RAW_DEVICE = &h20000003
const USBUSER_OP_SEND_RAW_COMMAND = &h20000004
const USBUSER_SET_ROOTPORT_FEATURE = &h20000005
const USBUSER_CLEAR_ROOTPORT_FEATURE = &h20000006
const USBUSER_GET_ROOTPORT_STATUS = &h20000007
const USBUSER_INVALID_REQUEST = &hfffffff0
const USBUSER_OP_MASK_DEVONLY_API = &h10000000
const USBUSER_OP_MASK_HCTEST_API = &h20000000
const USB_PACKETFLAG_LOW_SPEED = &h00000001
const USB_PACKETFLAG_FULL_SPEED = &h00000002
const USB_PACKETFLAG_HIGH_SPEED = &h00000004
const USB_PACKETFLAG_ASYNC_IN = &h00000008
const USB_PACKETFLAG_ASYNC_OUT = &h00000010
const USB_PACKETFLAG_ISO_IN = &h00000020
const USB_PACKETFLAG_ISO_OUT = &h00000040
const USB_PACKETFLAG_SETUP = &h00000080
const USB_PACKETFLAG_TOGGLE0 = &h00000100
const USB_PACKETFLAG_TOGGLE1 = &h00000200

type _USBUSER_REQUEST_HEADER
	UsbUserRequest as ULONG
	UsbUserStatusCode as USB_USER_ERROR_CODE
	RequestBufferLength as ULONG
	ActualBufferLength as ULONG
end type

type USBUSER_REQUEST_HEADER as _USBUSER_REQUEST_HEADER
type PUSBUSER_REQUEST_HEADER as _USBUSER_REQUEST_HEADER ptr

type _PACKET_PARAMETERS
	DeviceAddress as UCHAR
	EndpointAddress as UCHAR
	MaximumPacketSize as USHORT
	Timeout as ULONG
	Flags as ULONG
	DataLength as ULONG
	HubDeviceAddress as USHORT
	PortTTNumber as USHORT
	ErrorCount as UCHAR
	Pad(0 to 2) as UCHAR
	UsbdStatusCode as USBD_STATUS
	Data(0 to 3) as UCHAR
end type

type PACKET_PARAMETERS as _PACKET_PARAMETERS
type PPACKET_PARAMETERS as _PACKET_PARAMETERS ptr

type _USBUSER_SEND_ONE_PACKET
	Header as USBUSER_REQUEST_HEADER
	PacketParameters as PACKET_PARAMETERS
end type

type USBUSER_SEND_ONE_PACKET as _USBUSER_SEND_ONE_PACKET
type PUSBUSER_SEND_ONE_PACKET as _USBUSER_SEND_ONE_PACKET ptr

type _RAW_RESET_PORT_PARAMETERS
	PortNumber as USHORT
	PortStatus as USHORT
end type

type RAW_RESET_PORT_PARAMETERS as _RAW_RESET_PORT_PARAMETERS
type PRAW_RESET_PORT_PARAMETERS as _RAW_RESET_PORT_PARAMETERS ptr

type _USBUSER_RAW_RESET_ROOT_PORT
	Header as USBUSER_REQUEST_HEADER
	Parameters as RAW_RESET_PORT_PARAMETERS
end type

type USBUSER_RAW_RESET_ROOT_PORT as _USBUSER_RAW_RESET_ROOT_PORT
type PUSBUSER_RAW_RESET_ROOT_PORT as _USBUSER_RAW_RESET_ROOT_PORT ptr

type _RAW_ROOTPORT_FEATURE
	PortNumber as USHORT
	PortFeature as USHORT
	PortStatus as USHORT
end type

type RAW_ROOTPORT_FEATURE as _RAW_ROOTPORT_FEATURE
type PRAW_ROOTPORT_FEATURE as _RAW_ROOTPORT_FEATURE ptr

type _USBUSER_ROOTPORT_FEATURE_REQUEST
	Header as USBUSER_REQUEST_HEADER
	Parameters as RAW_ROOTPORT_FEATURE
end type

type USBUSER_ROOTPORT_FEATURE_REQUEST as _USBUSER_ROOTPORT_FEATURE_REQUEST
type PUSBUSER_ROOTPORT_FEATURE_REQUEST as _USBUSER_ROOTPORT_FEATURE_REQUEST ptr

type _RAW_ROOTPORT_PARAMETERS
	PortNumber as USHORT
	PortStatus as USHORT
end type

type RAW_ROOTPORT_PARAMETERS as _RAW_ROOTPORT_PARAMETERS
type PRAW_ROOTPORT_PARAMETERS as _RAW_ROOTPORT_PARAMETERS ptr

type _USBUSER_ROOTPORT_PARAMETERS
	Header as USBUSER_REQUEST_HEADER
	Parameters as RAW_ROOTPORT_PARAMETERS
end type

type USBUSER_ROOTPORT_PARAMETERS as _USBUSER_ROOTPORT_PARAMETERS
type PUSBUSER_ROOTPORT_PARAMETERS as _USBUSER_ROOTPORT_PARAMETERS ptr
const USB_HC_FEATURE_FLAG_PORT_POWER_SWITCHING = &h00000001
const USB_HC_FEATURE_FLAG_SEL_SUSPEND = &h00000002
const USB_HC_FEATURE_LEGACY_BIOS = &h00000004

type _USB_CONTROLLER_INFO_0
	PciVendorId as ULONG
	PciDeviceId as ULONG
	PciRevision as ULONG
	NumberOfRootPorts as ULONG
	ControllerFlavor as USB_CONTROLLER_FLAVOR
	HcFeatureFlags as ULONG
end type

type USB_CONTROLLER_INFO_0 as _USB_CONTROLLER_INFO_0
type PUSB_CONTROLLER_INFO_0 as _USB_CONTROLLER_INFO_0 ptr

type _USBUSER_CONTROLLER_INFO_0
	Header as USBUSER_REQUEST_HEADER
	Info0 as USB_CONTROLLER_INFO_0
end type

type USBUSER_CONTROLLER_INFO_0 as _USBUSER_CONTROLLER_INFO_0
type PUSBUSER_CONTROLLER_INFO_0 as _USBUSER_CONTROLLER_INFO_0 ptr

type _USB_UNICODE_NAME
	Length as ULONG
	String(0 to 0) as WCHAR
end type

type USB_UNICODE_NAME as _USB_UNICODE_NAME
type PUSB_UNICODE_NAME as _USB_UNICODE_NAME ptr

type _USBUSER_CONTROLLER_UNICODE_NAME
	Header as USBUSER_REQUEST_HEADER
	UnicodeName as USB_UNICODE_NAME
end type

type USBUSER_CONTROLLER_UNICODE_NAME as _USBUSER_CONTROLLER_UNICODE_NAME
type PUSBUSER_CONTROLLER_UNICODE_NAME as _USBUSER_CONTROLLER_UNICODE_NAME ptr

type _USB_PASS_THRU_PARAMETERS
	FunctionGUID as GUID
	ParameterLength as ULONG
	Parameters(0 to 3) as UCHAR
end type

type USB_PASS_THRU_PARAMETERS as _USB_PASS_THRU_PARAMETERS
type PUSB_PASS_THRU_PARAMETERS as _USB_PASS_THRU_PARAMETERS ptr

type _USBUSER_PASS_THRU_REQUEST
	Header as USBUSER_REQUEST_HEADER
	PassThru as USB_PASS_THRU_PARAMETERS
end type

type USBUSER_PASS_THRU_REQUEST as _USBUSER_PASS_THRU_REQUEST
type PUSBUSER_PASS_THRU_REQUEST as _USBUSER_PASS_THRU_REQUEST ptr

type _WDMUSB_POWER_STATE as long
enum
	WdmUsbPowerNotMapped = 0
	WdmUsbPowerSystemUnspecified = 100
	WdmUsbPowerSystemWorking
	WdmUsbPowerSystemSleeping1
	WdmUsbPowerSystemSleeping2
	WdmUsbPowerSystemSleeping3
	WdmUsbPowerSystemHibernate
	WdmUsbPowerSystemShutdown
	WdmUsbPowerDeviceUnspecified = 200
	WdmUsbPowerDeviceD0
	WdmUsbPowerDeviceD1
	WdmUsbPowerDeviceD2
	WdmUsbPowerDeviceD3
end enum

type WDMUSB_POWER_STATE as _WDMUSB_POWER_STATE

type _USB_POWER_INFO
	SystemState as WDMUSB_POWER_STATE
	HcDevicePowerState as WDMUSB_POWER_STATE
	HcDeviceWake as WDMUSB_POWER_STATE
	HcSystemWake as WDMUSB_POWER_STATE
	RhDevicePowerState as WDMUSB_POWER_STATE
	RhDeviceWake as WDMUSB_POWER_STATE
	RhSystemWake as WDMUSB_POWER_STATE
	LastSystemSleepState as WDMUSB_POWER_STATE
	CanWakeup as BOOLEAN
	IsPowered as BOOLEAN
end type

type USB_POWER_INFO as _USB_POWER_INFO
type PUSB_POWER_INFO as _USB_POWER_INFO ptr

type _USBUSER_POWER_INFO_REQUEST
	Header as USBUSER_REQUEST_HEADER
	PowerInformation as USB_POWER_INFO
end type

type USBUSER_POWER_INFO_REQUEST as _USBUSER_POWER_INFO_REQUEST
type PUSBUSER_POWER_INFO_REQUEST as _USBUSER_POWER_INFO_REQUEST ptr

type _USB_OPEN_RAW_DEVICE_PARAMETERS
	PortStatus as USHORT
	MaxPacketEp0 as USHORT
end type

type USB_OPEN_RAW_DEVICE_PARAMETERS as _USB_OPEN_RAW_DEVICE_PARAMETERS
type PUSB_OPEN_RAW_DEVICE_PARAMETERS as _USB_OPEN_RAW_DEVICE_PARAMETERS ptr

type _USBUSER_OPEN_RAW_DEVICE
	Header as USBUSER_REQUEST_HEADER
	Parameters as USB_OPEN_RAW_DEVICE_PARAMETERS
end type

type USBUSER_OPEN_RAW_DEVICE as _USBUSER_OPEN_RAW_DEVICE
type PUSBUSER_OPEN_RAW_DEVICE as _USBUSER_OPEN_RAW_DEVICE ptr

type _USB_CLOSE_RAW_DEVICE_PARAMETERS
	xxx as ULONG
end type

type USB_CLOSE_RAW_DEVICE_PARAMETERS as _USB_CLOSE_RAW_DEVICE_PARAMETERS
type PUSB_CLOSE_RAW_DEVICE_PARAMETERS as _USB_CLOSE_RAW_DEVICE_PARAMETERS ptr

type _USBUSER_CLOSE_RAW_DEVICE
	Header as USBUSER_REQUEST_HEADER
	Parameters as USB_CLOSE_RAW_DEVICE_PARAMETERS
end type

type USBUSER_CLOSE_RAW_DEVICE as _USBUSER_CLOSE_RAW_DEVICE
type PUSBUSER_CLOSE_RAW_DEVICE as _USBUSER_CLOSE_RAW_DEVICE ptr

type _USB_SEND_RAW_COMMAND_PARAMETERS
	Usb_bmRequest as UCHAR
	Usb_bRequest as UCHAR
	Usb_wVlaue as USHORT
	Usb_wIndex as USHORT
	Usb_wLength as USHORT
	DeviceAddress as USHORT
	MaximumPacketSize as USHORT
	Timeout as ULONG
	DataLength as ULONG
	UsbdStatusCode as USBD_STATUS
	Data(0 to 3) as UCHAR
end type

type USB_SEND_RAW_COMMAND_PARAMETERS as _USB_SEND_RAW_COMMAND_PARAMETERS
type PUSB_SEND_RAW_COMMAND_PARAMETERS as _USB_SEND_RAW_COMMAND_PARAMETERS ptr

type _USBUSER_SEND_RAW_COMMAND
	Header as USBUSER_REQUEST_HEADER
	Parameters as USB_SEND_RAW_COMMAND_PARAMETERS
end type

type USBUSER_SEND_RAW_COMMAND as _USBUSER_SEND_RAW_COMMAND
type PUSBUSER_SEND_RAW_COMMAND as _USBUSER_SEND_RAW_COMMAND ptr

type _USB_BANDWIDTH_INFO
	DeviceCount as ULONG
	TotalBusBandwidth as ULONG
	Total32secBandwidth as ULONG
	AllocedBulkAndControl as ULONG
	AllocedIso as ULONG
	AllocedInterrupt_1ms as ULONG
	AllocedInterrupt_2ms as ULONG
	AllocedInterrupt_4ms as ULONG
	AllocedInterrupt_8ms as ULONG
	AllocedInterrupt_16ms as ULONG
	AllocedInterrupt_32ms as ULONG
end type

type USB_BANDWIDTH_INFO as _USB_BANDWIDTH_INFO
type PUSB_BANDWIDTH_INFO as _USB_BANDWIDTH_INFO ptr

type _USBUSER_BANDWIDTH_INFO_REQUEST
	Header as USBUSER_REQUEST_HEADER
	BandwidthInformation as USB_BANDWIDTH_INFO
end type

type USBUSER_BANDWIDTH_INFO_REQUEST as _USBUSER_BANDWIDTH_INFO_REQUEST
type PUSBUSER_BANDWIDTH_INFO_REQUEST as _USBUSER_BANDWIDTH_INFO_REQUEST ptr

type _USB_BUS_STATISTICS_0
	DeviceCount as ULONG
	CurrentSystemTime as LARGE_INTEGER
	CurrentUsbFrame as ULONG
	BulkBytes as ULONG
	IsoBytes as ULONG
	InterruptBytes as ULONG
	ControlDataBytes as ULONG
	PciInterruptCount as ULONG
	HardResetCount as ULONG
	WorkerSignalCount as ULONG
	CommonBufferBytes as ULONG
	WorkerIdleTimeMs as ULONG
	RootHubEnabled as BOOLEAN
	RootHubDevicePowerState as UCHAR
	Unused as UCHAR
	NameIndex as UCHAR
end type

type USB_BUS_STATISTICS_0 as _USB_BUS_STATISTICS_0
type PUSB_BUS_STATISTICS_0 as _USB_BUS_STATISTICS_0 ptr

type _USBUSER_BUS_STATISTICS_0_REQUEST
	Header as USBUSER_REQUEST_HEADER
	BusStatistics0 as USB_BUS_STATISTICS_0
end type

type USBUSER_BUS_STATISTICS_0_REQUEST as _USBUSER_BUS_STATISTICS_0_REQUEST
type PUSBUSER_BUS_STATISTICS_0_REQUEST as _USBUSER_BUS_STATISTICS_0_REQUEST ptr

type _USB_DRIVER_VERSION_PARAMETERS
	DriverTrackingCode as ULONG
	USBDI_Version as ULONG
	USBUSER_Version as ULONG
	CheckedPortDriver as BOOLEAN
	CheckedMiniportDriver as BOOLEAN
	USB_Version as USHORT
end type

type USB_DRIVER_VERSION_PARAMETERS as _USB_DRIVER_VERSION_PARAMETERS
type PUSB_DRIVER_VERSION_PARAMETERS as _USB_DRIVER_VERSION_PARAMETERS ptr

type _USBUSER_GET_DRIVER_VERSION
	Header as USBUSER_REQUEST_HEADER
	Parameters as USB_DRIVER_VERSION_PARAMETERS
end type

type USBUSER_GET_DRIVER_VERSION as _USBUSER_GET_DRIVER_VERSION
type PUSBUSER_GET_DRIVER_VERSION as _USBUSER_GET_DRIVER_VERSION ptr

type _USB_USB2HW_VERSION_PARAMETERS
	Usb2HwRevision as UCHAR
end type

type USB_USB2HW_VERSION_PARAMETERS as _USB_USB2HW_VERSION_PARAMETERS
type PUSB_USB2HW_VERSION_PARAMETERS as _USB_USB2HW_VERSION_PARAMETERS ptr

type _USBUSER_GET_USB2HW_VERSION
	Header as USBUSER_REQUEST_HEADER
	Parameters as USB_USB2HW_VERSION_PARAMETERS
end type

type USBUSER_GET_USB2HW_VERSION as _USBUSER_GET_USB2HW_VERSION
type PUSBUSER_GET_USB2HW_VERSION as _USBUSER_GET_USB2HW_VERSION ptr

type _USBUSER_REFRESH_HCT_REG
	Header as USBUSER_REQUEST_HEADER
	Flags as ULONG
end type

type USBUSER_REFRESH_HCT_REG as _USBUSER_REFRESH_HCT_REG
type PUSBUSER_REFRESH_HCT_REG as _USBUSER_REFRESH_HCT_REG ptr

end extern
